package com.lei.chinese_herbal_medicine.Service.Impl;

import com.lei.chinese_herbal_medicine.Entity.PageData;
import com.lei.chinese_herbal_medicine.Entity.Result;
import com.lei.chinese_herbal_medicine.Entity.UserInfo;
import com.lei.chinese_herbal_medicine.Mapper.UserInfoMapper;
import com.lei.chinese_herbal_medicine.Service.UserInfoService;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * (UserInfo)表服务实现类
 *
 * @author makejava
 * @since 2024-01-18 10:06:42
 */
@Service("userInfoService")
public class UserInfoServiceImpl implements UserInfoService {
    @Resource
    private UserInfoMapper userInfoMapper;
    public UserInfo login(UserInfo userInfo){
        if (userInfo==null) return null;
        if(userInfo.getUsername()==null||"".equals(userInfo.getUsername().trim()))return null;
        if(userInfo.getPassword()==null||"".equals(userInfo.getPassword().trim()))return null;
        UserInfo info=userInfoMapper.selectByUser(userInfo);
        if(info!=null){
            info.setPassword("");
            return info;
        }
        return null;
    }

    @Override
    public boolean register(UserInfo userInfo) {
        UserInfo info=new UserInfo();
        info.setUsername(userInfo.getUsername());
        if(userInfoMapper.selectByUser(info)!=null){
            return false;
        }
        return userInfoMapper.insertSelective(userInfo)==1;
    }

    @Override
    public boolean updateUserInfo(UserInfo u) {
        return userInfoMapper.updateByPrimaryKeySelective(u)==1;
    }

    @Override
    public UserInfo getUserInfo(String userId) {
        return userInfoMapper.selectByPrimaryKey(userId);
    }

    @Override
    public List<UserInfo> getUserList(UserInfo userInfo, PageData pageData) {
        pageData.setCount(userInfoMapper.selectCount());
        return userInfoMapper.selectByUserInfo(userInfo,pageData);
    }

    @Override
    public boolean deleteUser(String id) {
        return userInfoMapper.deleteByPrimaryKey(id)==1;
    }
}


